package com.ruoyi.discuss.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.discuss.domain.Bigtopic;
import com.ruoyi.discuss.service.IBigtopicService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 话题Controller
 *
 * @author ruoyi
 * @date 2023-12-14
 */
@RestController
@RequestMapping("/discuss/bigtopic")
public class BigtopicController extends BaseController
{
    @Autowired
    private IBigtopicService bigtopicService;

    /**
     * 查询话题列表
     */
    @PreAuthorize("@ss.hasPermi('discuss:bigtopic:list')")
    @GetMapping("/list")
    public TableDataInfo list(Bigtopic bigtopic)
    {
        startPage();
        List<Bigtopic> list = bigtopicService.selectBigtopicList(bigtopic);
        return getDataTable(list);
    }

    /**
     * 导出话题列表
     */
    @PreAuthorize("@ss.hasPermi('discuss:bigtopic:export')")
    @Log(title = "话题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Bigtopic bigtopic)
    {
        List<Bigtopic> list = bigtopicService.selectBigtopicList(bigtopic);
        ExcelUtil<Bigtopic> util = new ExcelUtil<Bigtopic>(Bigtopic.class);
        util.exportExcel(response, list, "话题数据");
    }

    /**
     * 获取话题详细信息
     */
    @PreAuthorize("@ss.hasPermi('discuss:bigtopic:query')")
    @GetMapping(value = "/{topicid}")
    public AjaxResult getInfo(@PathVariable("topicid") Long topicid)
    {
        return success(bigtopicService.selectBigtopicByTopicid(topicid));
    }

    /**
     * 新增话题
     */
    @PreAuthorize("@ss.hasPermi('discuss:bigtopic:add')")
    @Log(title = "话题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Bigtopic bigtopic)
    {
        return toAjax(bigtopicService.insertBigtopic(bigtopic));
    }  @PostMapping("/addPoint")
    public AjaxResult addPoint(@RequestBody Bigtopic bigtopic)
    {
        return toAjax(bigtopicService.addPoint(bigtopic));
    }

    /**
     * 修改话题
     */
    @PreAuthorize("@ss.hasPermi('discuss:bigtopic:edit')")
    @Log(title = "话题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Bigtopic bigtopic)
    {
        return toAjax(bigtopicService.updateBigtopic(bigtopic));
    }

    /**
     * 删除话题
     */
    @PreAuthorize("@ss.hasPermi('discuss:bigtopic:remove')")
    @Log(title = "话题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{topicids}")
    public AjaxResult remove(@PathVariable Long[] topicids)
    {
        return toAjax(bigtopicService.deleteBigtopicByTopicids(topicids));
    }
}
